//
//  YXDateHelpObject.m
//  LaiApp_OC
//
//  Created by Jonas on 16/11/15.
//  Copyright © 2016年 Softtek. All rights reserved.
//

#import "YXDateHelpObject.h"

@interface YXDateHelpObject ()

@property (nonatomic, strong) NSDateFormatter *formate;

@end

static YXDateHelpObject *yxDate = nil;

@implementation YXDateHelpObject

+ (YXDateHelpObject *)manager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        yxDate = [[YXDateHelpObject alloc] init];
    });
    return yxDate;
}

- (instancetype)init {
    
    if (self = [super init]) {
        _formate = [[NSDateFormatter alloc] init];
    }
    return self;
    
}

//返回传入格式的日期字符
- (NSString *)getStrFromDateFormat:(NSString *)format Date:(NSDate *)date {
    
    [_formate setDateFormat:format];
    return [_formate stringFromDate:date];
    
}

//获取下一个月的时间
- (NSDate*)getNextMonth:(NSDate*)_date {
    
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *comps = [cal components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:_date];
    
    NSInteger year  = comps.year;
    NSInteger month = comps.month;
    NSInteger day   = comps.day;
    
    // NSLog(@"%d === %d === %d",year,month,day);
    
    NSDate* rt = nil;
    
    if (day <= 28 || month == 12) {
        
        comps.month = month+1;
        rt = [cal dateFromComponents:comps];
        
    } else {
        
        NSString* ss = [NSString stringWithFormat:@"%ld-%d-3", (long)year, month+1];
        [_formate setDateFormat:@"yyyy-MM-dd"];
        
        NSDate* the_month = [_formate dateFromString:ss];
        NSRange rng = [cal rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:the_month];
        NSInteger day_in_month = rng.length;
        
        NSString* datestring = [NSString stringWithFormat:@"%ld-%d-%d", (long)year, month+1, MIN(day, day_in_month)];
        rt = [_formate dateFromString:datestring];
        
        //NSLog(@" ss = %@  the_month = %@ day_in_month = %ld datestring = %@ rt = %@",ss,the_month,(long)day_in_month,datestring,rt);
    }
    
    
    
    return rt;
}

//获取上个月的时间
- (NSDate*)getPreviousMonth:(NSDate*)_date
{
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *comps = [cal components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:_date];
    
    NSInteger year  = comps.year;
    NSInteger month = comps.month;
    NSInteger day   = comps.day;
    
    // NSLog(@"%d === %d === %d 0000",year,month,day);
    
    NSDate* rt = nil;
    
    if (day <= 28 || month == 1) {
        
        comps.month = month-1;
        rt = [cal dateFromComponents:comps];
        
    } else {
        
        NSString* ss = [NSString stringWithFormat:@"%ld-%d-3", (long)year, month-1];
        [_formate setDateFormat:@"yyyy-MM-dd"];
        NSDate* the_month = [_formate dateFromString:ss];
        NSRange rng = [cal rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:the_month];
        NSInteger day_in_month = rng.length;
        
        NSString* datestring = [NSString stringWithFormat:@"%ld-%d-%d", (long)year, month-1, MIN(day, day_in_month)];
        rt = [_formate dateFromString:datestring];
        
        //NSLog(@" ss = %@  the_month = %@ day_in_month = %ld datestring = %@ rt = %@",ss,the_month,(long)day_in_month,datestring,rt);
        
    }
    return rt;
}

//获取本月第一天是星期几
- (NSInteger)currentFirstDay:(NSDate *)date {
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    [calendar setFirstWeekday:2];//1.mon
    NSDateComponents *comp = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:date];
    [comp setDay:1];
    NSDate *firstDayOfMonthDate = [calendar dateFromComponents:comp];
    
    NSUInteger firstWeekday = [calendar ordinalityOfUnit:NSCalendarUnitWeekday inUnit:NSCalendarUnitWeekOfMonth forDate:firstDayOfMonthDate];
    return firstWeekday;
}

//获取本月总天数
- (NSInteger)currentMonthOfDay:(NSDate *)date {
    NSRange totaldaysInMonth = [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:date];
    return totaldaysInMonth.length;
}

//判断两个月份是不是一样的
- (BOOL)checkSameMonth:(NSDate*)_month1 AnotherMonth:(NSDate*)_month2 {
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents* m1 = [cal components:NSCalendarUnitYear|NSCalendarUnitMonth fromDate:_month1];
    NSDateComponents* m2 = [cal components:NSCalendarUnitYear|NSCalendarUnitMonth fromDate:_month2];
    BOOL rt = NO;
    if ((m1.year == m2.year) && (m1.month == m2.month))
    {
        rt = YES;
    }
    return rt;
}

//获取一个月有多少行
- (NSInteger)getRows:(NSDate *)myDate {
    NSDate *firstday;
    [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitMonth startDate:&firstday interval:NULL forDate:myDate];
    NSUInteger zhouji =[[NSCalendar currentCalendar] ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitWeekOfMonth forDate:firstday];
    NSRange daysOfMonth = [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:myDate];
    //该月的行数
    NSInteger shenyu = daysOfMonth.length - (8 - zhouji);
    NSInteger hangshu;
    hangshu = shenyu % 7 > 0 ? shenyu/7 + 2 : shenyu/7 + 1;
    return hangshu;
}

//字符串返回时间
- (NSDate *)getDataFromStrFormat:(NSString *)format String:(NSString *)str {
    
    [_formate setDateFormat:format];
    return [_formate dateFromString:str];
    
}

//判断两天是不是同一天
- (BOOL)checkSameDate:(NSString *)date1 AnotherDate:(NSDate *)date2 {
    
    [_formate setDateFormat:@"yyyy-MM-dd"];
//    NSString *str1 = [format stringFromDate:date1];
    NSString *str2 = [_formate stringFromDate:date2];
    return [date1 isEqualToString:str2];
    
}

//获取某天零点时间
- (NSDate *)getStartDateWithDate:(NSDate *)date {
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date];
//    NSDate *startDate = [calendar dateFromComponents:components];
    return [calendar dateFromComponents:components];
    
}

/**
 * 判断两天是不是同一天
 */
- (BOOL)isSameDate:(NSDate *)date1 AnotherDate:(NSDate *)date2 {

    NSCalendar* calendar = [NSCalendar currentCalendar];
    
    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay;
    NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
    
    return [comp1 day]   == [comp2 day] &&
    [comp1 month] == [comp2 month] &&
    [comp1 year]  == [comp2 year];

}


/**
 * 判断两天是不是同一月
 */
- (BOOL)isSameMonth:(NSDate *)date1 AnotherDate:(NSDate *)date2 {
    
    NSCalendar* calendar = [NSCalendar currentCalendar];
    
    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay;
    NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
    
    return [comp1 month] == [comp2 month] &&
    [comp1 year]  == [comp2 year];
}


/**
 * 判断月数-------
 */
- (NSInteger)currentMonth:(NSDate *)date {
    
    NSCalendar* calendar = [NSCalendar currentCalendar];
    
    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay;
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date];
    
    return [comp2 month];
}


+ (int)compareDate:(NSString*)date01 withDate:(NSString*)date02{
    int ci;
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-M-dd"];
    NSDate *dt1 = [[NSDate alloc] init];
    NSDate *dt2 = [[NSDate alloc] init];
    dt1 = [df dateFromString:date01];
    dt2 = [df dateFromString:date02];
    NSComparisonResult result = [dt1 compare:dt2];
    switch (result)
    {
            //date02比date01大
        case NSOrderedAscending: ci=1; break;
            //date02比date01小
        case NSOrderedDescending: ci=-1; break;
            //date02=date01
        case NSOrderedSame: ci=0; break;
        default: NSLog(@"erorr dates %@, %@", dt2, dt1); break;
    }
    return ci;
}

/**
 将时间字符串转换成新的时间字符串
 
 @param oldStrDate 旧的时间
 @param oldFormat 旧的格式
 @param newFormat 新的时间格式
 @return 返回
 */
- (NSString *)getStrDateFromStrDate:(NSString *)oldStrDate OldFormat:(NSString *)oldFormat ByNewFormat:(NSString *)newFormat {
 
    [_formate setDateFormat:oldFormat];
    NSDate *oldDate = [_formate dateFromString:oldStrDate];
    [_formate setDateFormat:newFormat];
    return [_formate stringFromDate:oldDate];
    
}

/**
 获取某个时间前后时间
 
 @param currentDate 当前时间
 @param lead 距离时间
 @param timeType 时间类型(0-年  1-月 2-日 3-时 4-分 5-秒)
 @return 返回结果时间
 */
- (NSDate *)getEarlyOrLaterDate:(NSDate *)currentDate LeadTime:(NSInteger)lead Type:(NSInteger)timeType {
    
    NSCalendar *calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *dateCom = [[NSDateComponents alloc] init];
    if (timeType == 0) {
        [dateCom setYear:lead];
    } else if (timeType == 1) {
        [dateCom setMonth:lead];
    } else if (timeType == 2) {
        [dateCom setDay:lead];
    } else if (timeType == 3) {
        [dateCom setHour:lead];
    } else if (timeType == 4) {
        [dateCom setMinute:lead];
    } else if (timeType == 5) {
        [dateCom setSecond:lead];
    }
    
    return [calendar dateByAddingComponents:dateCom toDate:currentDate options:0];
    
}

- (NSString *)getWeekTimeType:(NSInteger)type selDate:(NSDate *)selDate
{
    //type是0代表是周一-----1代表是周日------
    NSDate *nowDate = selDate;
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *comp = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSDayCalendarUnit fromDate:nowDate];
    // 获取今天是周几
    NSInteger weekDay = [comp weekday];
    // 获取几天是几号
    NSInteger day = [comp day];
    
    // 计算当前日期和本周的星期一和星期天相差天数
    long firstDiff,lastDiff;
    //    weekDay = 1;
    if (weekDay == 1)
    {
        firstDiff = -6;
        lastDiff = 0;
    }
    else
    {
        firstDiff = [calendar firstWeekday] - weekDay + 1;
        lastDiff = 8 - weekDay;
    }
    
    // 在当前日期(去掉时分秒)基础上加上差的天数
    NSDateComponents *firstDayComp = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit  fromDate:nowDate];
    [firstDayComp setDay:day + firstDiff];
    NSDate *firstDayOfWeek = [calendar dateFromComponents:firstDayComp];
    
    NSDateComponents *lastDayComp = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit   fromDate:nowDate];
    [lastDayComp setDay:day + lastDiff];
    NSDate *lastDayOfWeek = [calendar dateFromComponents:lastDayComp];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy/MM/dd"];
    NSString *firstDay = [formatter stringFromDate:firstDayOfWeek];
    NSString *lastDay = [formatter stringFromDate:lastDayOfWeek];
    if (type == 0) {
        return firstDay;
    }
    else {
        return lastDay;
    }
}

//获取一周时间 数组
- (NSMutableArray *)getCurrentWeeksWithFirstDiff:(NSInteger)first lastDiff:(NSInteger)last{
    NSMutableArray *eightArr = [[NSMutableArray alloc] init];
    for (NSInteger i = first; i < last + 1; i ++) {
        //从现在开始的24小时
        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];         [dateFormatter setDateFormat:@"M月d日"];
        NSString *dateStr = [dateFormatter stringFromDate:curDate];//几月几号
        //        NSString *dateStr = @"5月31日";
        NSDateFormatter *weekFormatter = [[NSDateFormatter alloc] init];
        [weekFormatter setDateFormat:@"EEEE"];//星期几 @"HH:mm 'on' EEEE MMMM d"];
        NSString *weekStr = [weekFormatter stringFromDate:curDate];
        //组合时间
        NSString *strTime = [NSString stringWithFormat:@"%@(%@)",dateStr,weekStr];          [eightArr addObject:strTime];
    }
    return eightArr;
}

+ (NSString *)getMonthBeginAndEndWith:(NSString *)dateStr{
    
    NSDateFormatter *format=[[NSDateFormatter alloc] init];
    [format setDateFormat:@"yyyy/MM/dd"];
    NSDate *newDate=[format dateFromString:dateStr];
    double interval = 0;
    NSDate *beginDate = nil;
    NSDate *endDate = nil;
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    [calendar setFirstWeekday:2];//设定周一为周首日
    BOOL ok = [calendar rangeOfUnit:NSMonthCalendarUnit startDate:&beginDate interval:&interval forDate:newDate];
    //分别修改为 NSDayCalendarUnit NSWeekCalendarUnit NSYearCalendarUnit
    if (ok) {
        endDate = [beginDate dateByAddingTimeInterval:interval-1];
    }else {
        return @"";
    }
    NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
    [myDateFormatter setDateFormat:@"YYYY.MM.dd"];
    NSString *beginString = [myDateFormatter stringFromDate:beginDate];
    NSString *endString = [myDateFormatter stringFromDate:endDate];
//    NSString *s = [NSString stringWithFormat:@"%@-%@",beginString,endString];
    return endString;
}

//获取某一天的1天前的时间
- (NSDate *)getThreeDayAgoTime:(NSDate *)nowDate {
    NSInteger dis = 3; //前后的天数
    NSDate * theDate;
    
    if(dis!=0)
    {
        NSTimeInterval  oneDay = 24*60*60*1;  //1天的长度
        
        //theDate = [nowDate initWithTimeIntervalSinceNow: + oneDay*dis ];
        //or
        theDate = [nowDate initWithTimeInterval:- oneDay*dis sinceDate:nowDate];
    }
    else
    {
        theDate = nowDate;
    }
    return theDate;
}



//获取最近index天时间数组
-(NSMutableArray *)latelyTime:(NSInteger) index{
    NSMutableArray *eightArr = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < index; i ++) {
        //从现在开始的24小时
        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"M月dd日"];
        NSString *dateStr = [dateFormatter stringFromDate:curDate];//几月几号
        NSDateFormatter *weekFormatter = [[NSDateFormatter alloc] init];
        [weekFormatter setDateFormat:@"EEEE"];//星期几 @"HH:mm 'on' EEEE MMMM d"];
        NSString *weekStr = [weekFormatter stringFromDate:curDate];
        
        //转换英文为中文
//        NSString *chinaStr = [self cTransformFromE:weekStr];
        
        //组合时间
        NSString *strTime = [NSString stringWithFormat:@"%@ %@",dateStr,weekStr];
        [eightArr addObject:strTime];
    }
    return eightArr;
}


//获取最近index天时间数组---年月日的------------
-(NSMutableArray *)latelyTimeYearMonthDay:(NSInteger) index{
    NSMutableArray *eightArr = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < index; i ++) {
        //从现在开始的24小时
        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy/MM/dd"];
        NSString *dateStr = [dateFormatter stringFromDate:curDate];//几月几号
        
        //转换英文为中文
        //        NSString *chinaStr = [self cTransformFromE:weekStr];
        
        //组合时间
//        NSString *strTime = [NSString stringWithFormat:@"%@ %@",dateStr,weekStr];
        [eightArr addObject:dateStr];
    }
    return eightArr;
}

//转换英文为中文
-(NSString *)cTransformFromE:(NSString *)theWeek{
    NSString *chinaStr;
    if(theWeek){
        if([theWeek isEqualToString:@"Monday"]){
            chinaStr = @"星期一";
        }else if([theWeek isEqualToString:@"Tuesday"]){
            chinaStr = @"星期二";
        }else if([theWeek isEqualToString:@"Wednesday"]){
            chinaStr = @"星期三";
        }else if([theWeek isEqualToString:@"Thursday"]){
            chinaStr = @"星期四";
        }else if([theWeek isEqualToString:@"Friday"]){
            chinaStr = @"星期五";
        }else if([theWeek isEqualToString:@"Saturday"]){
            chinaStr = @"星期六";
        }else if([theWeek isEqualToString:@"Sunday"]){
            chinaStr = @"星期日";
        }
    }
    return chinaStr;
}


//接机时候获取最近index天时间数组
-(NSMutableArray *)receptPlaneFourDate:(NSInteger)index {
    NSMutableArray *eightArr = [[NSMutableArray alloc] init];
    
    for (int i = -1; i < index; i ++) {
        //从现在开始的24小时
        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"M月d日"];
        NSString *dateStr = [dateFormatter stringFromDate:curDate];//几月几号
        
        //转换英文为中文
        //        NSString *chinaStr = [self cTransformFromE:weekStr];
        
        [eightArr addObject:dateStr];
    }
    return eightArr;
}

//接机时候获取最近index天时间数组年月日-----------------------
-(NSMutableArray *)receptPlaneFourYearMonthDate:(NSInteger)index {
    NSMutableArray *eightArr = [[NSMutableArray alloc] init];
    
    for (int i = -1; i < index; i ++) {
        //从现在开始的24小时
        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy/MM/dd"];
        NSString *dateStr = [dateFormatter stringFromDate:curDate];//几月几号
        
        //转换英文为中文
        //        NSString *chinaStr = [self cTransformFromE:weekStr];
        
        [eightArr addObject:dateStr];
    }
    return eightArr;
}

/**
 2  * @method
 3  *
 4  * @brief 获取两个日期之间的天数
 5  * @param fromDate       起始日期
 6  * @param toDate         终止日期
 7  * @return    总天数
 8  */
+ (NSInteger)numberOfDaysWithFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate{
         NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth
    | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
        NSDateComponents *comp = [calendar components:unit
                                            fromDate:fromDate
                                                                                        toDate:toDate
                                                                                       options:NSCalendarWrapComponents];
    NSInteger dayCom = comp.day;
    NSInteger hourCom = comp.hour;
    NSInteger minCom = comp.minute;
    NSInteger finalDayCom = 0;
    if (minCom == 0 && hourCom == 0) {
        finalDayCom = dayCom;
    }else {
        finalDayCom = dayCom + 1;
    }
    return finalDayCom;
}


//好的当前时间年月日
- (NSString *)getCurentTime:(NSString *)dateFormateSet dateN:(NSDate *)dateN{
    
    NSDate *date = dateN;
    NSDateFormatter *dateFormate = [[NSDateFormatter alloc]init];
    [dateFormate setDateFormat:dateFormateSet]; //@"YYYY年MM月dd日"];
    return [dateFormate stringFromDate:date];
    
}


//获取当前的东西
- (NSDateComponents *)getNSDateComponents{
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDate *now;
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags =NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour |NSCalendarUnitMinute | NSCalendarUnitSecond;
    now=[NSDate date];
    comps = [calendar components:unitFlags fromDate:now];
    
    return comps;
}

//此方法可获取年月日时分秒周几
- (NSString *)getCurentWeek{
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDate *now;
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags =NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour |NSCalendarUnitMinute | NSCalendarUnitSecond;
    now=[NSDate date];
    comps = [calendar components:unitFlags fromDate:now];
    
    NSString *weekDay = @"";
    switch (comps.weekday) {
        case 1:
            weekDay = @"星期日";
            break;
        case 2:
            weekDay = @"星期一";
            break;
        case 3:
            weekDay = @"星期二";
            break;
        case 4:
            weekDay = @"星期三";
            break;
        case 5:
            weekDay = @"星期四";
            break;
        case 6:
            weekDay = @"星期五";
            break;
            
        default:
            weekDay = @"星期六";
            break;
    }
    return [NSString stringWithFormat:@"%ld年%ld月%ld日 %@",(long)[comps year],(long)[comps month],(long)[comps day],weekDay];
}

//获取今天某天是周几 只需要传入一个date
-(NSString *)getBaseWeekly:(NSDate *)dayDate{
    NSInteger  I =  [[NSCalendar currentCalendar] ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitWeekOfMonth forDate:dayDate];
    NSString *weekDay = @"";
    switch (I) {
        case 1:
            weekDay = @"星期日";
            break;
        case 2:
            weekDay = @"星期一";
            break;
        case 3:
            weekDay = @"星期二";
            break;
        case 4:
            weekDay = @"星期三";
            break;
        case 5:
            weekDay = @"星期四";
            break;
        case 6:
            weekDay = @"星期五";
            break;
            
        default:
            weekDay = @"星期六";
            break;
    }
    return weekDay;
}
//得到datepicker上的信息得到年月日
- (NSString *)getDatePickerMessge:(NSDate *)dateMessge{
    NSDateFormatter *dateFormate = [[NSDateFormatter alloc]init];
    [dateFormate setDateFormat:@"yyyy年MM月dd日"];
    return [dateFormate stringFromDate:dateMessge];
}


//获取最近index天时间数组---日  周------------
-(NSMutableArray *)latelySevenDateDay:(NSInteger) index{
    NSMutableArray *eightArr = [[NSMutableArray alloc] init];
    for (int i = 0; i < index; i ++) {
        //从现在开始的24小时
        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"d"];
        NSString *dateStr = [dateFormatter stringFromDate:curDate];//几号
//        NSDateFormatter *weekFormatter = [[NSDateFormatter alloc] init];
//        [weekFormatter setDateFormat:@"EEEE"];//星期几 @"HH:mm 'on' EEEE MMMM d"];
//        NSString *weekStr = [weekFormatter stringFromDate:curDate];
//
//        NSArray *tmpArray = [weekStr componentsSeparatedByString:@"星期"];
//        weekStr = tmpArray.lastObject;
        //转换英文为中文
        //        NSString *chinaStr = [self cTransformFromE:weekStr];
        
        //组合时间
//        NSString *strTime = [NSString stringWithFormat:@"%@ %@",dateStr,weekStr];
        [eightArr addObject:dateStr];
    }
    return eightArr;
}

//获取最近index天时间数组周------------
-(NSMutableArray *)latelySevenWeakDay:(NSInteger) index{
    NSMutableArray *eightArr = [[NSMutableArray alloc] init];
    for (int i = 0; i < index; i ++) {
        //从现在开始的24小时
        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
        NSDateFormatter *weekFormatter = [[NSDateFormatter alloc] init];
        [weekFormatter setDateFormat:@"EEEE"];//星期几 @"HH:mm 'on' EEEE MMMM d"];
        NSString *weekStr = [weekFormatter stringFromDate:curDate];
        
        NSArray *tmpArray = [weekStr componentsSeparatedByString:@"星期"];
        weekStr = tmpArray.lastObject;
        //转换英文为中文
        //        NSString *chinaStr = [self cTransformFromE:weekStr];
        
        //组合时间
        [eightArr addObject:weekStr];
    }
    return eightArr;
}


//获取今天某天是周几 只需要传入一个date
//-(NSString *)getBaseWeek:(NSString *)weekStr{
//    switch (weekStr) {
//        case @"星期日":
//            weekDay = @"星期日";
//            break;
//            
//        default:
//            break;
//    }
//    switch (weekStr) {
//        case @"星期日":
//            weekDay = @"星期日";
//            break;
//        case 2:
//            weekDay = @"星期一";
//            break;
//        case 3:
//            weekDay = @"星期二";
//            break;
//        case 4:
//            weekDay = @"星期三";
//            break;
//        case 5:
//            weekDay = @"星期四";
//            break;
//        case 6:
//            weekDay = @"星期五";
//            break;
//            
//        default:
//            weekDay = @"星期六";
//            break;
//    }
//    return weekDay;
//}


@end
